package ptumall.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ptumall.dao.TesteeDao;
import ptumall.dao.UsersDao;
import ptumall.model.Testee;
import ptumall.model.Users;
import ptumall.service.RelationService;

import java.util.List;

@Service
public class RelationServiceImpl implements RelationService {
    @Autowired
    private UsersDao usersDao;

    @Autowired
    private TesteeDao testeeDao;

    @Override
    public List<Testee> getRelationsByOpenid(String openid) throws Exception {
        // 1. 验证用户存在性
        Users user = usersDao.findByOpenid(openid);
        if (user == null) {
            throw new RuntimeException("用户不存在");
        }

        // 2. 获取关联检测人
        return testeeDao.findByUserId(user.getUserId());
    }
}
